package com.px.user.mapper;

import com.px.user.entity.Cheat;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface CheatMapper {

    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into cheat (creatorId,name,intro,downloadUrl) values " +
            "(#{creatorId},#{name},#{intro},#{downloadUrl})")
    void insert(Cheat cheat);


    @Select("select * from cheat where creatorId=#{id}")
    List<Cheat> findByCreatorId(Long id);


    @Update("update cheat set name=ifnull(#{name},name),intro=ifnull(#{intro},intro)," +
            "downloadUrl=ifnull(#{downloadUrl},downloadUrl) " +
            "where creatorId=#{creatorId} and id=#{id}")
    void update(Cheat cheat);

    @Delete("delete from cheat where creatorId=#{creatorId} and id=#{id}")
    void deleteByCreatorId(Map map);

    @Delete("delete from cheat where id=#{id}")
    void delete(Integer id);
}
